﻿using CSharpDay12Nov10.Adapters.Interfaces;
using CSharpDay12Nov10.Data;
using CSharpDay12Nov10.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CSharpDay12Nov10.Adapters.Adapters
{
    public class TaskAdapter : ITaskAdapter
    {
        public List<ToDoVM> GetAllTasks(string userId)
        {
            List<ToDoVM> model;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                model = db.ToDos.Where(x => x.UserId == userId && x.IsDeleted == false).Select(x => new ToDoVM()
                {
                    DateCompleted = x.DateCompleted,
                    DateCreated = x.DateCreated,
                    DateDeleted = x.DateDeleted,
                    IsComplete = x.IsComplete,
                    IsDeleted = x.IsDeleted,
                    TaskToDo = x.TaskToDo,
                    ToDoId = x.ToDoId,
                    UserId = userId
                }).ToList();
            }
            return model;
        }
    }
}